Skip to content

fix: allow duplicate request content access#470

Merged
vbreuss merged 1 commit into
mainfrom
topic/fix-duplicate-validation
Feb 8, 2026
Merged

fix: allow duplicate request content access#470
vbreuss merged 1 commit into
mainfrom
topic/fix-duplicate-validation

Conversation

@vbreuss

@vbreuss vbreuss commented Feb 8, 2026

Copy link
Copy Markdown
Member

Enables matching/verifying HttpContent multiple times (setup + verify) without consuming the underlying content stream, including additional support for .NET Framework where HttpContent can be disposed automatically.

Key Changes:

  • Added tests to ensure setups and verifications can both read the same request content.
  • Updated HttpContent parameter matching to be HttpRequestMessage-aware and to restore stream position after reading.
  • Updated source generator output for HttpClient.Send* on .NET Framework to persist request content bytes for later matching.

@vbreuss vbreuss self-assigned this Feb 8, 2026
Copilot AI review requested due to automatic review settings February 8, 2026 14:05
@vbreuss vbreuss added the bug Something isn't working label Feb 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables matching/verifying HttpContent multiple times (setup + verify) without consuming the underlying content stream, including additional support for .NET Framework where HttpContent can be disposed automatically.

Changes:

  • Added tests to ensure setups and verifications can both read the same request content.
  • Updated HttpContent parameter matching to be HttpRequestMessage-aware and to restore stream position after reading.
  • Updated source generator output for HttpClient.Send* on .NET Framework to persist request content bytes for later matching.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Tests/Mockolate.Tests/Web/ItExtensionsTests.IsHttpContentTests.WithStringTests.cs Adds regression test covering setup+verify reading string content twice
Tests/Mockolate.Tests/Web/ItExtensionsTests.IsHttpContentTests.WithBytesTests.cs Adds regression test covering setup+verify reading bytes content twice
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.PutTests.cs Strengthens verification to also assert JSON body content
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.PostTests.cs Strengthens verification to also assert JSON body content
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.PatchTests.cs Strengthens verification to also assert JSON body content
Source/Mockolate/Web/ItExtensions.HttpContent.cs Makes content matching request-aware and resets stream position after reads
Source/Mockolate/Web/IHttpRequestMessagePropertyParameter.cs Introduces request-aware parameter interface
Source/Mockolate/Web/HttpClientExtensions.cs Passes HttpRequestMessage to request-aware parameters during matching
Source/Mockolate.SourceGenerators/Sources/Sources.ForMock.cs Emits .NET Framework-specific content persistence for HttpClient.Send*
Source/Mockolate.SourceGenerators/Sources/Sources.ForMock.Extensions.cs Removes prior special-casing for HttpClient.Send* setups

Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs
Comment thread Source/Mockolate.SourceGenerators/Sources/Sources.ForMock.cs
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs
@sonarqubecloud

sonarqubecloud Bot commented Feb 8, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Feb 8, 2026

Copy link
Copy Markdown

Test Results

    21 files  ± 0      21 suites  ±0   5m 50s ⏱️ +20s
 2 715 tests + 2   2 714 ✅ + 2  1 💤 ±0  0 ❌ ±0 
18 221 runs  +14  18 220 ✅ +14  1 💤 ±0  0 ❌ ±0 

Results for commit dd31596. ± Comparison against base commit 3fe1f4f.

@github-actions

github-actions Bot commented Feb 8, 2026

Copy link
Copy Markdown

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.60GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.102
[Host] : .NET 10.0.2 (10.0.2, 10.0.225.61305), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.550 μs 0.0114 μs 0.0096 μs 0.2270 - 3.73 KB
Simple_Moq 178.002 μs 0.8512 μs 0.7108 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.715 μs 0.0745 μs 0.0697 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.072 μs 0.0578 μs 0.0512 μs 0.4959 - 8.11 KB

@vbreuss vbreuss merged commit eff28c4 into main Feb 8, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/fix-duplicate-validation branch February 8, 2026 14:11
@github-actions

github-actions Bot commented Feb 8, 2026

Copy link
Copy Markdown

This is addressed in release v1.4.0.

@github-actions github-actions Bot added the state: released The issue is released label Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The content reader does not reset the stream correctly

2 participants